package cn.gemiman.daoyi.module.cms.controller.app.articlecategory;

import cn.gemiman.daoyi.framework.common.pojo.CommonResult;
import cn.gemiman.daoyi.framework.common.pojo.PageResult;
import cn.gemiman.daoyi.framework.common.util.object.BeanUtils;
import cn.gemiman.daoyi.framework.web.core.util.WebFrameworkUtils;
import cn.gemiman.daoyi.module.cms.controller.admin.articlecategory.vo.CmsArticleCategoryPageReqVO;
import cn.gemiman.daoyi.module.cms.controller.admin.articlecategory.vo.CmsArticleCategoryRespVO;
import cn.gemiman.daoyi.module.cms.dal.dataobject.articlecategory.CmsArticleCategoryDO;
import cn.gemiman.daoyi.module.cms.service.articlecategory.CmsArticleCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static cn.gemiman.daoyi.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 文章栏目")
@RestController
@RequestMapping("/cms/article-category")
@Validated
public class AppCmsArticleCategoryController {

    @Resource
    private CmsArticleCategoryService articleCategoryService;

    @GetMapping("/get")
    @Operation(summary = "获得文章栏目")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<CmsArticleCategoryRespVO> getArticleCategory(@RequestParam("id") Long id) {
        CmsArticleCategoryDO articleCategory = articleCategoryService.getArticleCategory(id);
        return success(BeanUtils.toBean(articleCategory, CmsArticleCategoryRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得文章栏目分页")
    public CommonResult<PageResult<CmsArticleCategoryRespVO>> getArticleCategoryPage(@Valid CmsArticleCategoryPageReqVO pageReqVO) {
        pageReqVO.setAppId(WebFrameworkUtils.getAppId());
        PageResult<CmsArticleCategoryDO> pageResult = articleCategoryService.getArticleCategoryPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CmsArticleCategoryRespVO.class));
    }

}
